package com.rsk.api;


import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysCompanyTypesService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.QueryParam;
import java.util.List;
import java.util.Map;

/**
 * 机构类型
 * @author myr
 */

@RestController
@RequestMapping(value="/sys/comtype")
public class SysCompanyTypesApi {

    @Reference(interfaceClass = SysCompanyTypesService.class, protocol = "dubbo")
    private  SysCompanyTypesService sysCompanyTypesService;

    /**
     * 删除机构类型
     */

    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/delSysCompanyType" )
    public Result<String> delSysCompanysType(@QueryParam("id") Long id,
                                         @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyTypesService.delSysCompanysType(id, operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     * 修改机构类型
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/updateSysCompanyType")
    public Result<String> updateSysCompanysType(@QueryParam("id") Long id,
                                            @QueryParam("typeName") String typeName,
                                            @QueryParam("remarks")  String remarks,
                                            @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyTypesService.updateSysCompanysType(id,typeName,remarks,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     * 新增机构类型
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/saveSysCompanyType")
    public Result<String> saveSysCompanysType(@QueryParam("id") Long id,
                                                @QueryParam("typeName") String typeName,
                                                @QueryParam("typeCode") String typeCode,
                                                @QueryParam("remarks")  String remarks,
                                                @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyTypesService.saveSysCompanysType(id,typeName,typeCode,remarks,operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     * 查询机构类型
     * @param nowPage
     * @param pageSize
     * @param typeName
     * @param Authorization
     * @return
     */

    @SuppressWarnings("rawtypes")
    @PostMapping(value = "/selectSysCompanyType")
    public Result<List<Map>> selectSysCompanyType(@QueryParam("nowPage") Integer nowPage,
                                                  @QueryParam("pageSize") Integer pageSize,
                                                  @QueryParam("typeName") String typeName,
                                                  @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        List<Map> page = sysCompanyTypesService.selectSysComapnyType(typeName,nowPage,pageSize);
        return ResultBuilder.success(page,ResultCode.SUCCESS);

    }

}
